package algo;

import java.util.ArrayList;

public class RockPaperScissors 
{
	public Result play(RPSEnum p1,RPSEnum p2)
	{
		//return Result.LOST;//premier test qui va fail car de l'autre cote win
		Result rs_test=null;
		switch(p1)
		{case ROCK:
			switch (p2)
			{case ROCK:
				rs_test=Result.TIE;
				break;
				
			case PAPER:
				rs_test=Result.LOST;
				break;
				
			case SCISSOR:
				rs_test=Result.WIN;
				break;
			}
			
			break;
			
		case PAPER:
			switch (p2)
			{case ROCK:
				rs_test=Result.WIN;
				break;
				
			case PAPER:
				rs_test=Result.TIE;
				break;
				
			case SCISSOR:
				rs_test=Result.LOST;
				break;
			}
			break;
			
		case SCISSOR:
			switch (p2)
			{case ROCK:
				rs_test=Result.LOST;
				break;
				
			case PAPER:
				rs_test=Result.WIN;
				break;
				
			case SCISSOR:
				rs_test=Result.TIE;
				break;
			}
			break;
		
		}
		return rs_test;
	}
	
	public Result play (Player p1, Player p2)
	{ 
		ArrayList <RPSEnum> enum1=p1.getListdecoups();
		ArrayList <RPSEnum> enum2=p2.getListdecoups();
		
		int resultatp1=0;
		int resultatp2=0;
		Result result=null;
		int i=0;
		for (RPSEnum tmp:enum1)
		//do
		{
		
		
		result=play(enum1.get(i),enum2.get(i));
		
		System.out.println("youhou "+result);
		
		if (result==Result.TIE )
		{
			resultatp1=resultatp1+1; 
			resultatp2=resultatp2+1; 
			System.out.println("je suis en tie result p1 "+resultatp1+"resultat "+resultatp2);
		}
			if  (result==Result.WIN)
			{
				resultatp1=resultatp1+1; 
				System.out.println("je suis en win result p1 "+resultatp1+"resultat "+resultatp2);
			}
	    if (result==Result.LOST)
	    {
			resultatp2=resultatp2+1;
			System.out.println("je suis en lost result p1 "+resultatp1+"resultat "+resultatp2);
	    }
	    /*p1.getNextMove();
	    p2.getNextMove();*/
		i++;
		}//while (p1.getNextMove()!=null && p2.getNextMove()!=null);
		
		if (resultatp1 < resultatp2)
		{ p1.setResult(0);
		p2.setResult(2); 
		p1.setScore(resultatp1); 
		p2.setScore(resultatp2); 
		return Result.LOST;
		}
		if (resultatp1 > resultatp2)
		{ p1.setResult(2);p2.setResult(0); p1.setScore(resultatp1); p2.setScore(resultatp2);return Result.WIN;}
		else 
			 {p1.setResult(1);p2.setResult(1);p1.setScore(resultatp1); p2.setScore(resultatp2);return Result.TIE;}
		
		
		
		
	}

}
